﻿#pragma execution_character_set("utf-8")
#include <Windows.h>
#include <stdio.h>
#include <d3d11.h>
#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_impl_win32.h"
#include "imgui_impl_dx11.h"
#include <thread>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <MinHook.h>

#include "MainUI.h"
#include "../dll_main.h"
#include "../Settings/Settings.h"
#include "../static/Resources/Sounds.h"
#include "../img/texture.h"
#include <fstream>  // 确保包含这个头文件
#include <cstring>  // 用于 memset
#include "../function/PlayerData/PlayerData.h"
#pragma comment(lib, "winmm.lib")


// 在全局变量中添加
static bool showSaveConfirmDialog = false;
static bool showDeleteConfirmDialog = false;
static bool showResetConfirmDialog = false;

static std::string pendingSaveFilename;
static std::string pendingSaveMessage;
static std::string pendingDeleteFilename;

extern std::vector<ID3D11ShaderResourceView*> g_textures;

void MenuAnimationManager::UpdateAnimation(bool menuOpen, float deltaTime) {
    const float animSpeed = 18.0f;
    if (s_lastMenuState != menuOpen) {
        s_lastMenuState = menuOpen;
    }

    float targetAlpha = menuOpen ? 1.0f : 0.0f;
    if (s_alphaAnim < targetAlpha) {
        s_alphaAnim = fmin(s_alphaAnim + deltaTime * animSpeed, targetAlpha);
    }
    else if (s_alphaAnim > targetAlpha) {
        s_alphaAnim = fmax(s_alphaAnim - deltaTime * animSpeed, targetAlpha);
    }
}

float MenuAnimationManager::GetAlpha() {
    return s_alphaAnim;
}

void MenuAnimationManager::ResetAnimation(bool menuOpen) {
    s_alphaAnim = menuOpen ? 1.0f : 0.0f;
    s_lastMenuState = menuOpen;
}
 
bool IconTextButton(const char* label, ImTextureID texture, const ImVec2& imageSize,
    const ImVec2& buttonSize, bool isActive,
    const ImVec4& activeColor, const ImVec4& normalColor) {
    ImGuiWindow* window = ImGui::GetCurrentWindow();
    if (window->SkipItems)
        return false;

    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;

    const ImVec2 label_size = ImGui::CalcTextSize(label);

    ImVec2 actualSize = buttonSize;
    if (buttonSize.x == 0) {
        actualSize.x = imageSize.x + style.ItemInnerSpacing.x + label_size.x + style.FramePadding.x * 2;
    }
    if (buttonSize.y == 0) {
        actualSize.y = ImMax(imageSize.y, label_size.y) + style.FramePadding.y * 2;
    }

    ImGuiID id = window->GetID(label);
    ImVec2 pos = window->DC.CursorPos;

    ImVec2 bbMax = ImVec2(pos.x + actualSize.x, pos.y + actualSize.y);
    ImRect bb(pos, bbMax);
    ImGui::ItemSize(bb, style.FramePadding.y);
    if (!ImGui::ItemAdd(bb, id))
        return false;

    bool hovered, held;
    bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);

    if (isActive) {
        // 绘制激活状态的边框
        window->DrawList->AddRect(bb.Min, bb.Max,
            ImGui::GetColorU32(activeColor),
            style.FrameRounding, 0, 2.2f);
    }

    if (texture) {
        ImVec2 iconPos = bb.Min;
        iconPos.x += style.FramePadding.x;
        iconPos.y += (actualSize.y - imageSize.y) * 0.5f;
        ImVec2 iconMax = ImVec2(iconPos.x + imageSize.x, iconPos.y + imageSize.y);
        window->DrawList->AddImage(texture, iconPos, iconMax);
    }

    ImVec2 textPos = bb.Min;
    textPos.x += (texture ? imageSize.x + style.ItemInnerSpacing.x : 0) + style.FramePadding.x;
    textPos.y += (actualSize.y - label_size.y) * 0.5f;

    ImU32 textColor = isActive ? ImGui::GetColorU32(ImVec4(4.0f, 4.0f, 1.0f, 1.0f)) :
        ImGui::GetColorU32(ImGuiCol_Text);
    window->DrawList->AddText(textPos, textColor, label);

    return pressed;
}

static int current_weapon_id = 0;
static bool weapon_acquired_this_frame = false;
static bool firstTime = true;

void CreateStyledChildWindow(
    const char* id,
    const ImVec2& pos,
    const ImVec2& size,
    const ImVec4& bg_color,
    const ImVec4& border_color,
    std::function<void()> contentCallback,
    float rounding = 8.0f,
    float border_width = 2.0f)
{
    ImGui::SetCursorPos(pos);
    ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, rounding);
    ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, rounding);
    ImGui::PushStyleVar(ImGuiStyleVar_GrabRounding, 15.0f);
    ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 15.0f);
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(15, 15));
    ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(15, 15));
    ImGui::PushStyleColor(ImGuiCol_ChildBg, bg_color);
    ImGui::PushStyleColor(ImGuiCol_Border, border_color);
    // 在绘制复选框前添加样式设置
    ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.16f, 0.29f, 0.48f, 0.60f));  // 默认背景
    ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0.26f, 0.39f, 0.58f, 0.80f));  // 悬停背景
    ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(0.36f, 0.49f, 0.68f, 0.90f));  // 激活背景
    ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(0.90f, 0.90f, 1.00f, 1.00f));  // 勾选标记
    ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.20f, 0.50f, 1.00f, 0.50f));  // 边框颜色
    ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);  // 边框粗细

    if (ImGui::BeginChild(id, size, true,
        ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
    {
        if (ImDrawList* draw_list = ImGui::GetWindowDrawList()) {
            ImVec2 window_pos = ImGui::GetWindowPos();
            draw_list->AddRectFilled(window_pos, ImVec2(window_pos.x + size.x, window_pos.y + size.y),
                ImGui::GetColorU32(ImGuiCol_ChildBg), rounding);
            draw_list->AddRect(window_pos, ImVec2(window_pos.x + size.x, window_pos.y + size.y),
                ImGui::GetColorU32(ImGuiCol_Border), rounding,
                ImDrawFlags_RoundCornersAll, border_width);
        }

        if (contentCallback) contentCallback();
    }
    ImGui::EndChild();

    // 修正：弹出所有推入的样式和颜色
    ImGui::PopStyleColor(7);  // 弹出7个颜色
    ImGui::PopStyleVar(7);    // 弹出7个样式变量（6个常规 + 1个FrameBorderSize）
}

bool ColorPickerWithCheckbox(const char* label, bool* enabled, ImColor* color1, ImColor* color2 = nullptr) {
    bool changed = false;
    float color_button_pos = color2 ? 300.0f : 335.0f;
    float checkbox_pos = 370.0f;

    ImGui::Text("%s", label);

    if (color1) {
        ImGui::SameLine(color_button_pos);
        if (ImGui::ColorButton(("##" + std::string(label) + "_color1").c_str(), *color1)) {
            ImGui::OpenPopup(("##" + std::string(label) + "_picker1").c_str());
        }

        if (ImGui::BeginPopup(("##" + std::string(label) + "_picker1").c_str())) {
            changed |= ImGui::ColorPicker4(
                "##picker1",
                (float*)color1,
                ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayRGB
            );
            ImGui::EndPopup();
        }
        color_button_pos += 35.0f;
    }

    if (color2) {
        ImGui::SameLine(color_button_pos);
        if (ImGui::ColorButton(("##" + std::string(label) + "_color2").c_str(), *color2)) {
            ImGui::OpenPopup(("##" + std::string(label) + "_picker2").c_str());
        }

        if (ImGui::BeginPopup(("##" + std::string(label) + "_picker2").c_str())) {
            changed |= ImGui::ColorPicker4(
                "##picker2",
                (float*)color2,
                ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayRGB
            );
            ImGui::EndPopup();
        }
    }

    ImGui::SameLine(checkbox_pos);
    changed |= ImGui::Checkbox(("##" + std::string(label) + "_checkbox").c_str(), enabled);
    return changed;
}

// 多个面板状态管理
namespace popup_state {
    inline std::unordered_map<std::string, bool> show_settings;
    inline std::unordered_map<std::string, ImVec2> popup_positions;
}

void CloseAllPopupWindows() {
    for (auto& pair : popup_state::show_settings) {
        pair.second = false;
    }
}

// 通用设置面板函数（修复点击问题）
bool IconCheckbox(const char* id, const char* label, ImTextureID texture, const ImVec2& iconSize, bool& enabled, const ImVec2& windows_pos,
    const std::function<void()>& settingsContent) {
    bool changed = false;

    // 生成唯一ID
    std::string uniqueId = std::string(id) + "_" + label;

    ImGui::Text("%s", label);
    ImGui::SameLine(330);

    // 设置透明背景
    ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
    ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
    ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
    ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));

    // 绘制图标按钮
    bool buttonClicked = ImGui::ImageButton(uniqueId.c_str(), texture, iconSize);

    // 在点击时立即保存图片按钮的位置
    if (buttonClicked) {
        popup_state::popup_positions[uniqueId] = ImVec2(ImGui::GetItemRectMin().x + 15, ImGui::GetItemRectMin().y + 15);
    }

    // 恢复样式
    ImGui::PopStyleColor(4);

    ImGui::SameLine(370);
    std::string checkboxId = "##" + uniqueId + "_checkbox";

    // 保存原始状态
    bool originalEnabled = enabled;

    // 显示复选框
    if (ImGui::Checkbox(checkboxId.c_str(), &enabled)) {
        changed = true;

        // 检查互斥逻辑
        if (enabled) {
            // 获取当前标签的字符串
            std::string currentLabel = id;
        }
    }
    // 处理按钮点击状态切换
    if (buttonClicked) {
        popup_state::show_settings[uniqueId] = !popup_state::show_settings[uniqueId];
    }

    // 渲染弹出面板
    if (popup_state::show_settings[uniqueId]) {
        ImGui::SetNextWindowPos(popup_state::popup_positions[uniqueId], ImGuiCond_Appearing);
        ImGui::SetNextWindowSize(windows_pos);

        // 设置窗口圆角和背景色
        ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 8.0f);
        ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.1f, 0.1f, 0.1f, 0.95f));

        // 使用唯一的窗口ID
        std::string windowTitle = "Settings_" + uniqueId;
        if (ImGui::Begin(windowTitle.c_str(), nullptr,
            ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoResize |
            ImGuiWindowFlags_NoMove |
            ImGuiWindowFlags_NoScrollbar |
            ImGuiWindowFlags_NoCollapse |
            ImGuiWindowFlags_NoSavedSettings)) {

            // 调用设置内容回调函数
            if (settingsContent) {
                settingsContent();
            }
        }

        // 保存窗口是否被悬停的状态
        bool isWindowHovered = ImGui::IsWindowHovered();

        // 恢复样式
        ImGui::PopStyleColor();
        ImGui::PopStyleVar();
        ImGui::End();

        // 检查是否点击了窗口外部（不包括图标按钮）
        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !buttonClicked) {
            // 检查是否点击了ImGui区域
            bool clickedOnGui = ImGui::IsAnyItemHovered() || isWindowHovered;

            // 如果没有点击在ImGui区域，则关闭面板
            if (!clickedOnGui) {
                popup_state::show_settings[uniqueId] = false;
            }
        }

        // 或者按ESC键关闭
        if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
            popup_state::show_settings[uniqueId] = false;
        }
    }
    return changed;
}

// 辅助函数：创建武器选择下拉框（修复版本）
void DrawWeaponSelector(const char* label, int& current_weapon_id, int& setting_weapon_id, const std::unordered_map<int, std::string>& weapon_names) {
    ImGui::Text(u8"选择武器");
    ImGui::SameLine(190);
    ImGui::PushItemWidth(165);

    if (ImGui::BeginCombo(label, weapon_names.at(current_weapon_id).c_str())) {
        std::vector<int> weapon_ids;
        for (const auto& pair : weapon_names) {
            weapon_ids.push_back(pair.first);
        }
        std::sort(weapon_ids.begin(), weapon_ids.end());

        for (int id : weapon_ids) {
            bool is_selected = (current_weapon_id == id);
            if (ImGui::Selectable(weapon_names.at(id).c_str(), is_selected)) {
                current_weapon_id = id;
                setting_weapon_id = id;
            }
            if (is_selected) {
                ImGui::SetItemDefaultFocus();
            }
        }
        ImGui::EndCombo();
    }
}

// 辅助函数：获取当前武器ID（修复版本）
int GetCurrentWeaponID(bool& weapon_acquired_this_frame, int& selected_weapon) {
    static int current_weapon_id = 0;

    // 只在菜单打开的第一帧获取武器
    if (Menu::menu_open && !weapon_acquired_this_frame) {
        auto& playerDataManager = PlayerDataManager::GetInstance();
        auto localPlayer = playerDataManager.GetLocalPlayerData();

        if (WEAPON_NAMES.find(localPlayer.weaponID) != WEAPON_NAMES.end()) {
            current_weapon_id = localPlayer.weaponID;
            selected_weapon = localPlayer.weaponID;
        }
        weapon_acquired_this_frame = true;
    }
    else if (!Menu::menu_open) {
        // 菜单关闭时重置获取标志
        weapon_acquired_this_frame = false;
        current_weapon_id = selected_weapon;
    }
    else {
        current_weapon_id = selected_weapon;
    }

    return current_weapon_id;
}

namespace Menu {
    enum class MainPage {
        VIOLENCE,
        VISUAL,
        SKIN,
        SETTINGS,
        NONE
    };
    enum class VisualSubPage {
        ENEMY,
        TEAMMATE,
        LOCAL
    };
    enum class ViolenceSubPage {
        AIMBOT,
        TRAGEBOT,
    };

    enum class LegalSubPage {
        WEAPONSEIINGU,
        YAWEAPON
    };

    static MainPage currentMainPage = MainPage::VIOLENCE;
    static VisualSubPage currentVisualPage = VisualSubPage::ENEMY;
    static ViolenceSubPage currentViolencePage = ViolenceSubPage::AIMBOT;
    static LegalSubPage currentLegalPage = LegalSubPage::WEAPONSEIINGU;

    const ImVec4 BUTTON_COLOR = ImVec4(0.3f, 0.3f, 0.6f, 1.0f);
    const ImVec4 BUTTON_HOVER_COLOR = ImVec4(0.4f, 0.4f, 0.7f, 1.0f);
    const ImVec4 BUTTON_ACTIVE_COLOR = ImVec4(0.5f, 0.5f, 0.8f, 1.0f);

    const ImVec4 ACTIVE_COLOR = ImVec4(0.4f, 0.6f, 1.0f, 0.6f);
    const ImVec4 HOVER_COLOR = ImVec4(0.3f, 0.5f, 0.9f, 0.4f);
    const ImVec4 NORMAL_COLOR = ImVec4(0.133f, 0.338f, 0.586f, 0.940f);

    void SetNextBtbPos() {
        static float addposy = 0;
        ImGui::SetCursorPosY(ImGui::GetCursorPosY() + addposy);
        addposy += 70;
    }

    void DrawEnhancedTabButton(const char* label, VisualSubPage page, VisualSubPage& currentPage) {

        bool isActive = (currentPage == page);
        ImGui::PushStyleColor(ImGuiCol_Button, isActive ? ACTIVE_COLOR : NORMAL_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonHovered, isActive ? ACTIVE_COLOR : HOVER_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonActive, ACTIVE_COLOR);
        ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, isActive ? 1.0f : 0.0f);
        ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.5f, 0.8f, 1.0f, 0.8f));

        if (ImGui::Button(label, ImVec2(160, 40))) {
            currentPage = page;
        }

        ImGui::PopStyleColor(4);
        ImGui::PopStyleVar();
    }

    void DrawAimbotTabButton(const char* label, ViolenceSubPage page, ViolenceSubPage& currentViolencePage) {

        bool isActive = (currentViolencePage == page);
        ImGui::PushStyleColor(ImGuiCol_Button, isActive ? ACTIVE_COLOR : NORMAL_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonHovered, isActive ? ACTIVE_COLOR : HOVER_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonActive, ACTIVE_COLOR);
        ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, isActive ? 1.0f : 0.0f);
        ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.5f, 0.8f, 1.0f, 0.8f));

        if (ImGui::Button(label, ImVec2(160, 40))) {
            currentViolencePage = page;
        }

        ImGui::PopStyleColor(4);
        ImGui::PopStyleVar();
    }

    void DrawLefalTabButton(const char* label, LegalSubPage page, LegalSubPage& currentLegalPage) {

        bool isActive = (currentLegalPage == page);
        ImGui::PushStyleColor(ImGuiCol_Button, isActive ? ACTIVE_COLOR : NORMAL_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonHovered, isActive ? ACTIVE_COLOR : HOVER_COLOR);
        ImGui::PushStyleColor(ImGuiCol_ButtonActive, ACTIVE_COLOR);
        ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, isActive ? 1.0f : 0.0f);
        ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.5f, 0.8f, 1.0f, 0.8f));

        if (ImGui::Button(label, ImVec2(160, 40))) {
            currentLegalPage = page;
        }

        ImGui::PopStyleColor(4);
        ImGui::PopStyleVar();
    }

    void RenderNavigationBar(const ImVec2& windowPos) {
        auto draw = ImGui::GetWindowDrawList();
        const char* title = "Sy Hex";
        float titleFontSize = 40.f;
        ImVec2 titlePos = { windowPos.x + 30, windowPos.y + 12 };
        draw->AddText(font_E, titleFontSize, titlePos, ImColor(0, 255, 175, 255), title);

        ImVec2 titleSize = ImGui::CalcTextSize(title);
        float titleRightEdge = titlePos.x + titleSize.x;
        float buttonSpacing = 10.0f;
        float buttonsStartX = titleRightEdge + 120.0f;

        ImGui::SetCursorPos(ImVec2(buttonsStartX - windowPos.x, 33));
        ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
        ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12, 6));
        ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
        ImGui::SetWindowFontScale(1.2f);

        // 5. 定义颜色和尺寸
        const ImVec4 ACTIVE_COLOR = ImVec4(0.4f, 0.6f, 1.0f, 1.0f);
        const ImVec4 NORMAL_COLOR = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);

        const ImVec2 BUTTON_SIZE(130, 49);
        const ImVec2 ICON_SIZE(36, 36);

        // 检查纹理是否可用
        bool texturesAvailable = !g_textures.empty() && g_textures.size() >= 4;

         
        // 6. 绘制所有按钮（共享同一个背景面板）
        // 暴力按钮
        if (IconTextButton(u8"自瞄",
            texturesAvailable ? (ImTextureID)g_textures[0] : nullptr,
            ICON_SIZE, BUTTON_SIZE,
            currentMainPage == MainPage::VIOLENCE,
            ACTIVE_COLOR, NORMAL_COLOR)) {
            CloseAllPopupWindows(); // 关闭所有弹出窗口
            currentMainPage = MainPage::VIOLENCE;
        }
        ImGui::SameLine(0, buttonSpacing);

        // 视觉按钮
        if (IconTextButton(u8"视觉",
            texturesAvailable ? (ImTextureID)g_textures[1] : nullptr,
            ICON_SIZE, BUTTON_SIZE,
            currentMainPage == MainPage::VISUAL,
            ACTIVE_COLOR, NORMAL_COLOR)) {
            CloseAllPopupWindows(); // 关闭所有弹出窗口
            currentMainPage = MainPage::VISUAL;
        }
        ImGui::SameLine(0, buttonSpacing);

        // 杂项按钮
        if (IconTextButton(u8"杂项",
            texturesAvailable ? (ImTextureID)g_textures[2] : nullptr,
            ICON_SIZE, BUTTON_SIZE,
            currentMainPage == MainPage::SKIN,
            ACTIVE_COLOR, NORMAL_COLOR)) {
            CloseAllPopupWindows(); // 关闭所有弹出窗口
            currentMainPage = MainPage::SKIN;
        }
        ImGui::SameLine(0, buttonSpacing);

        // 设置按钮
        if (IconTextButton(u8"设置",
            texturesAvailable ? (ImTextureID)g_textures[3] : nullptr,
            ICON_SIZE, BUTTON_SIZE,
            currentMainPage == MainPage::SETTINGS,
            ACTIVE_COLOR, NORMAL_COLOR)) {
            CloseAllPopupWindows(); // 关闭所有弹出窗口
            currentMainPage = MainPage::SETTINGS;
        }


        ImGui::SameLine(0, buttonSpacing);
        ImGui::SetWindowFontScale(1.0f);
        ImGui::PopStyleVar(3);

        float lineY = windowPos.y + 65;
        draw->AddLine(
            ImVec2(windowPos.x, lineY),
            ImVec2(windowPos.x + windowSize.x - 25, lineY),
            IM_COL32(116, 116, 116, 255),
            1.0f
        );

    }

    void RenderContentArea() {
        ImGui::SetCursorPos(ImVec2(25, 90));
        ImGui::BeginChild("##ContentArea", ImVec2(windowSize.x - 25, 630), true,
            ImGuiWindowFlags_NoCollapse |
            ImGuiWindowFlags_NoResize |
            ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoScrollbar |      // 禁用滚动条
            ImGuiWindowFlags_NoScrollWithMouse | // 禁用鼠标滚动
            ImGuiWindowFlags_NoScrollbar |
            ImGuiWindowFlags_NoBackground);

        switch (currentMainPage) {
        case MainPage::VIOLENCE:
            RenderViolencePage();
            break;        
        case MainPage::VISUAL:
            RenderVisualPage();
            break;
        case MainPage::SKIN:
            RenderSkinPage();
            break;
        case MainPage::SETTINGS:
            RenderSettingsPage();
            break;
        default:
            RenderEmptyPage();
            break;
        }
        ImGui::EndChild();
    }

    void RenderFooter() {
        ImVec2 windowPos = ImGui::GetWindowPos();
        float lineY = windowPos.y + 720;
        auto draw = ImGui::GetWindowDrawList();
        draw->AddLine(
            ImVec2(windowPos.x + 25, lineY),
            ImVec2(windowPos.x + windowSize.x, lineY),
            IM_COL32(116, 116, 116, 255));

        ImGui::SetCursorPos(ImVec2(50, 737));

        ImGui::Text(u8"当前配置文件：");
        ImGui::SameLine();
        // 显示当前加载的配置文件名称，如果没有加载则显示"无"
        if (!currentlyLoadedConfig.empty()) {
            ImGui::TextColored(ImVec4(0.000f, 1.000f, 0.685f, 1.0f), currentlyLoadedConfig.c_str());
        }
        else {
            ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), u8"无");
        }
        ImGui::SameLine();
        // 保存按钮 - 单独一行
        if (ImGui::Button(u8"保存当前配置") && selectedCfgIndex >= 0) {
            // 检查当前选中的文件是否与已加载的文件一致
            if (!currentlyLoadedConfig.empty()) {
                // 用户选择"是"，执行保存
                saveConfig(currentlyLoadedConfig);

                showSaveSuccess = true;
                saveSuccessAlpha = 1.0f;
                saveSuccessTime = std::chrono::steady_clock::now();
            }
        }
        ImGui::SetCursorPos(ImVec2(990, 737));
        ImGui::TextColored(ImVec4(0.000f, 1.000f, 0.685f, 1.0f), "V1.2.0");
    }

    // 主渲染函数
    void RenderViolencePage() {
        // 左侧菜单栏
        CreateStyledChildWindow("##meun_Violence", ImVec2(10, 10), ImVec2(190, 610),
            ImVec4(0.084f, 0.124f, 0.210f, 0.429f),
            ImVec4(0.779f, 0.779f, 0.779f, 0.500f),
            []() {
                ImGui::SetWindowFontScale(1.2f);
                DrawAimbotTabButton(u8"瞄准机器人", ViolenceSubPage::AIMBOT, currentViolencePage);
                DrawAimbotTabButton(u8"扳机和压枪", ViolenceSubPage::TRAGEBOT, currentViolencePage);
                ImGui::SetWindowFontScale(1.0f);
            });

        switch (currentViolencePage) {
        case ViolenceSubPage::AIMBOT:
            // 自瞄设置区域
            CreateStyledChildWindow("##aimbot_1", ImVec2(210, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), u8"暴力自瞄");
                    ImGui::Separator();

                    // 自瞄总开关
                    IconCheckbox("aimbot", u8"开启自瞄", (ImTextureID)g_textures[3], ImVec2(25, 25),
                        all_settings::aimbot_anitaimbot::aimbot::open_aimbot.enabled, ImVec2(330, 100),
                        []() {
                            ImGui::Text("开启模式:");
                            ImGui::SameLine(220);
                            ImGui::PushItemWidth(100);
                            int aimbot_mode = static_cast<int>(all_settings::aimbot_anitaimbot::aimbot::open_aimbot.mode);
                            if (ImGui::Combo("##aim_mode", &aimbot_mode, "always\0targe\0hold\0")) {
                                all_settings::aimbot_anitaimbot::aimbot::open_aimbot.mode =
                                    static_cast<all_settings::targe_hole>(aimbot_mode);
                            }
                            ImGui::PopItemWidth();
                            ImGui::Text("快捷键:");
                            ImGui::SameLine(230);
                            KeySelector("open_aimbot_kjj", "Aimbot", all_settings::aimbot_anitaimbot::aimbot::open_aimbot.hotkey);
                        });

                    // 自瞄功能选项
                    ImGui::Text(u8"自动开火");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##autofire", &all_settings::aimbot_anitaimbot::aimbot::autofire);
                    if (all_settings::aimbot_anitaimbot::aimbot::autofire) {
                        ImGui::Text(u8"连续开火延迟");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##autofire_yc", &all_settings::aimbot_anitaimbot::aimbot::autofiree_yc, 0.0f, 1000.0f, "%.0f");
                    }

                    ImGui::Text(u8"镉墙锁");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##gqs", &all_settings::aimbot_anitaimbot::aimbot::gqs);

                    ImGui::Text(u8"自动急停");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##autostay", &all_settings::aimbot_anitaimbot::aimbot::autostop);

                    // 自瞄模式选择
                    ImGui::Text(u8"自瞄模式");
                    ImGui::SameLine(190);
                    ImGui::PushItemWidth(205);
                    int current_mode = static_cast<int>(all_settings::aimbot_anitaimbot::aimbot::current_aim_mode);
                    if (ImGui::Combo("##aim_mode", &current_mode, "普通自瞄\0静默自瞄\0")) {
                        all_settings::aimbot_anitaimbot::aimbot::current_aim_mode =
                            static_cast<all_settings::AimMode>(current_mode);
                    }

                    // 杂项设置
                    ImGui::Separator();
                    ImGui::TextColored(ImVec4(0.0f, 0.0f, 1.0f, 1.0f), u8"自瞄杂项");
                    ImGui::Separator();

                    ImGui::Text(u8"自动开镜");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##autoScoped", &all_settings::aimbot_anitaimbot::aimbot::autoScoped);

                    ImGui::Text(u8"队伍判断");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##team_pd", &all_settings::aimbot_anitaimbot::aimbot::team_pd);
                });

            // 武器专属设置区域
            CreateStyledChildWindow("##aimbot_2", ImVec2(630, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    // 在您的UI代码中使用：
                    static bool weapon_acquired_aimbot_frame = false;
                    int current_weapon_id = GetCurrentWeaponID(weapon_acquired_this_frame,
                        all_settings::aimbot_anitaimbot::aimbot::selected_weapon);

                    // 使用修复后的DrawWeaponSelector
                    DrawWeaponSelector("##aimbotweapon_select", current_weapon_id,
                        all_settings::aimbot_anitaimbot::aimbot::selected_weapon, WEAPON_NAMES);

                    if (all_settings::aimbot_anitaimbot::aimbot::aimbot_weapon_settings.count(current_weapon_id) == 0) {
                        all_settings::aimbot_anitaimbot::aimbot::aimbot_weapon_settings[current_weapon_id] =
                            all_settings::aimbot_anitaimbot::aimbot::WeaponSettings();
                    }

                    // 获取当前武器设置
                    auto* current_weapon_settings = &all_settings::aimbot_anitaimbot::aimbot::aimbot_weapon_settings[current_weapon_id];
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##weapon_enabled", &current_weapon_settings->enabled);

                    if (current_weapon_settings->enabled) {
                        // FOV设置
                        ImGui::Text(u8"自瞄范围(FOV)");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##aim_fov", &current_weapon_settings->fov, 0.1f, 180.0f, "%.1f");

                        ImGui::Text(u8"自瞄平滑");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##aimbot_smooth", &current_weapon_settings->aimbot_smooth, 0.0f, 100.0f, "%.0f");

                        ImGui::Text(u8"自动穿墙");
                        ImGui::SameLine(370);
                        ImGui::Checkbox("##autowall", &current_weapon_settings->autowall);

                        ImGui::Text(u8"自动穿墙阈值");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##autowall_fw", &current_weapon_settings->autowall_fw, 1.0f, 10.0f, "%.0f");
                        // 骨骼设置
                        ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), u8"骨骼设置");
                        ImGui::Text(u8"瞄准部位:");
                        ImGui::SameLine(190);
                        ImGui::PushItemWidth(205);

                        ImGuiStyle& style = ImGui::GetStyle();
                        float original_padding = style.FramePadding.x;
                        style.FramePadding.x = 10.0f;

                        const char* bone_items[] = {
                            u8"头部", u8"颈部", u8"脊椎", u8"骨盆",
                            u8"左臂", u8"右臂", u8"左腿", u8"右腿"
                        };

                        int current_bone = -1;
                        if (current_weapon_settings->bone_settings.head) current_bone = 0;
                        else if (current_weapon_settings->bone_settings.neck) current_bone = 1;
                        else if (current_weapon_settings->bone_settings.spine) current_bone = 2;
                        else if (current_weapon_settings->bone_settings.pelvis) current_bone = 3;
                        else if (current_weapon_settings->bone_settings.armUpper_L) current_bone = 4;
                        else if (current_weapon_settings->bone_settings.armUpper_R) current_bone = 5;
                        else if (current_weapon_settings->bone_settings.legUpper_L) current_bone = 6;
                        else if (current_weapon_settings->bone_settings.legUpper_R) current_bone = 7;

                        const char* preview_text = (current_bone >= 0 && current_bone < IM_ARRAYSIZE(bone_items)) ?
                            bone_items[current_bone] : u8"未选择";

                        if (ImGui::BeginCombo("##bone_select", preview_text)) {
                            for (int i = 0; i < IM_ARRAYSIZE(bone_items); i++) {
                                bool is_selected = (current_bone == i);
                                if (ImGui::Selectable(bone_items[i], is_selected)) {
                                    current_weapon_settings->bone_settings = {}; // 重置所有骨骼
                                    switch (i) {
                                    case 0: current_weapon_settings->bone_settings.head = true; break;
                                    case 1: current_weapon_settings->bone_settings.neck = true; break;
                                    case 2: current_weapon_settings->bone_settings.spine = true; break;
                                    case 3: current_weapon_settings->bone_settings.pelvis = true; break;
                                    case 4: current_weapon_settings->bone_settings.armUpper_L = true; break;
                                    case 5: current_weapon_settings->bone_settings.armUpper_R = true; break;
                                    case 6: current_weapon_settings->bone_settings.legUpper_L = true; break;
                                    case 7: current_weapon_settings->bone_settings.legUpper_R = true; break;
                                    }
                                }
                                if (is_selected) {
                                    ImGui::SetItemDefaultFocus();
                                }
                            }
                            ImGui::EndCombo();
                        }

                        style.FramePadding.x = original_padding;
                    }
                });
            break;

        case ViolenceSubPage::TRAGEBOT:
            // 扳机设置区域
            CreateStyledChildWindow("##target_bot_1", ImVec2(210, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    // 扳机总开关
                    IconCheckbox("aimbot_target_bot", u8"自动扳机总开关", (ImTextureID)g_textures[3], ImVec2(25, 25),
                        all_settings::aimbot_anitaimbot::Target_Bot::target_bot.enabled, ImVec2(330, 100),
                        []() {
                            ImGui::Text("开启模式:");
                            ImGui::SameLine(220);
                            ImGui::PushItemWidth(100);
                            int aimbot_mode = static_cast<int>(all_settings::aimbot_anitaimbot::Target_Bot::target_bot.mode);
                            if (ImGui::Combo("##aim_mode", &aimbot_mode, "always\0targe\0hold\0")) {
                                all_settings::aimbot_anitaimbot::Target_Bot::target_bot.mode =
                                    static_cast<all_settings::targe_hole>(aimbot_mode);
                            }
                            ImGui::PopItemWidth();
                            ImGui::Text("快捷键:");
                            ImGui::SameLine(230);
                            KeySelector("aimbot_target_bot_kjj", "aimbot_target_bot_kjj_aimbot",
                                all_settings::aimbot_anitaimbot::Target_Bot::target_bot.hotkey);
                        });

                    // 扳机功能选项
                    ImGui::Text(u8"自动刀");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##auto_knife", &all_settings::aimbot_anitaimbot::Target_Bot::auto_knife);

                    ImGui::Text(u8"自动电击枪");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##auto_taser", &all_settings::aimbot_anitaimbot::Target_Bot::auto_taser);


                    // 在您的UI代码中使用：
                    static bool weapon_acquired_Target_Bot_frame = false;
                    int current_weapon_id = GetCurrentWeaponID(weapon_acquired_Target_Bot_frame,
                        all_settings::aimbot_anitaimbot::Target_Bot::selected_weapon);

                    // 使用修复后的DrawWeaponSelector
                    DrawWeaponSelector("##Target_Botweapon_select", current_weapon_id,
                        all_settings::aimbot_anitaimbot::Target_Bot::selected_weapon, WEAPON_NAMES);

                    // 确保武器设置存在
                    if (all_settings::aimbot_anitaimbot::Target_Bot::target_bot_weapon_settings.count(current_weapon_id) == 0) {
                        all_settings::aimbot_anitaimbot::Target_Bot::target_bot_weapon_settings[current_weapon_id] =
                            all_settings::aimbot_anitaimbot::Target_Bot::target_botSettings();
                    }

                    auto* current_weapon_settings = &all_settings::aimbot_anitaimbot::Target_Bot::target_bot_weapon_settings[current_weapon_id];
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##weapon_enabled", &current_weapon_settings->enabled);

                    // 武器参数设置
                    if (current_weapon_settings->enabled) {
                        ImGui::Text(u8"扳机延迟");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##target_bot_yc", &current_weapon_settings->target_bot_yc, 1.0f, 100.0f, "%.0f");
                    }
                });

            // 压枪设置区域
            CreateStyledChildWindow("##target_bot_2", ImVec2(630, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    // 压枪总开关
                    ImGui::Text(u8"自动压枪总开关");
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##auto_knife", &all_settings::aimbot_anitaimbot::Weapon_RCS::Open_Weapon_RCS);

                    // 在您的UI代码中使用：
                    static bool weapon_acquired_Weapon_RCS_frame = false;
                    int current_weapon_id = GetCurrentWeaponID(weapon_acquired_Weapon_RCS_frame,
                        all_settings::aimbot_anitaimbot::Weapon_RCS::selected_weapon);

                    // 使用修复后的DrawWeaponSelector
                    DrawWeaponSelector("##Weapon_RCSweapon_select", current_weapon_id,
                        all_settings::aimbot_anitaimbot::Weapon_RCS::selected_weapon, WEAPON_NAMES);


                    // 确保武器设置存在
                    if (all_settings::aimbot_anitaimbot::Weapon_RCS::Weapon_RCS_settings.count(current_weapon_id) == 0) {
                        all_settings::aimbot_anitaimbot::Weapon_RCS::Weapon_RCS_settings[current_weapon_id] =
                            all_settings::aimbot_anitaimbot::Weapon_RCS::Weapon_RCSSettings();
                    }

                    auto* current_weapon_settings = &all_settings::aimbot_anitaimbot::Weapon_RCS::Weapon_RCS_settings[current_weapon_id];
                    ImGui::SameLine(370);
                    ImGui::Checkbox("##weapon_enabled", &current_weapon_settings->enabled);

                    // 压枪参数设置
                    if (current_weapon_settings->enabled) {
                        ImGui::Text(u8"垂直补偿");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##vertical", &current_weapon_settings->vertical, 0.0f, 4.0f, "%.1f");

                        ImGui::Text(u8"水平补偿");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##horizontal", &current_weapon_settings->horizontal, 0.0f, 4.0f, "%.1f");

                        ImGui::Text(u8"平滑");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##rcs_smooth", &current_weapon_settings->rcs_smooth, 0.0f, 10.0f, "%.1f");
                    }
                });
            break;
        }
    }

    void RenderVisualPage() {
        // 定义颜色常量
        const ImVec4 ACTIVE_COLOR = ImVec4(0.4f, 0.6f, 1.0f, 0.6f);
        const ImVec4 HOVER_COLOR = ImVec4(0.3f, 0.5f, 0.9f, 0.4f);
        const ImVec4 NORMAL_COLOR = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);

        // 左侧菜单栏
        CreateStyledChildWindow("##visual_menu", ImVec2(10, 10), ImVec2(190, 610),
            ImVec4(0.084f, 0.124f, 0.210f, 0.429f),
            ImVec4(0.779f, 0.779f, 0.779f, 0.500f),
            [&]() {
                ImGui::SetWindowFontScale(1.2f);
                DrawEnhancedTabButton(u8"敌人", VisualSubPage::ENEMY, currentVisualPage);
                DrawEnhancedTabButton(u8"队友", VisualSubPage::TEAMMATE, currentVisualPage);
                DrawEnhancedTabButton(u8"本地", VisualSubPage::LOCAL, currentVisualPage);
                ImGui::SetWindowFontScale(1.0f);
                ImGui::SetCursorPos(ImVec2(20, 480));
                ImGui::Text(u8"文字显示缩放");
                ImGui::PushItemWidth(160);
                ImGui::SliderFloat("##player_fov_fw", &all_settings::visual::text_font, 0.1f, 1.5f, "%.1f");
                ImGui::Text(u8"启用透视");
                ImGui::SameLine(150);
                ImGui::Checkbox("##ESP", &all_settings::visual::ESP);
            });

        // 根据当前子页面渲染不同内容
        switch (currentVisualPage) {
        case VisualSubPage::ENEMY:
            // 敌人设置面板
            CreateStyledChildWindow("##enemy_settings", ImVec2(210, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"启用敌人透视"); ImGui::SameLine(370);
                    ImGui::Checkbox("##enemy_esp", &all_settings::visual::enemy::enemy_visual);
                    ImGui::Separator();
                    ColorPickerWithCheckbox(u8"敌人方框",
                        &all_settings::visual::enemy::enemy_kuang_visual,
                        &all_settings::visual::enemy::enemy_kuang_visual_color_ks);
                    ColorPickerWithCheckbox(u8"敌人名字",
                        &all_settings::visual::enemy::enemy_name_visual,
                        &all_settings::visual::enemy::enemy_name_visual_color);
                    ColorPickerWithCheckbox(u8"敌人血条",
                        &all_settings::visual::enemy::enemy_ShowHealth_visual,
                        &all_settings::visual::enemy::enemy_Health_color);
                    ColorPickerWithCheckbox(u8"敌人骨骼",
                        &all_settings::visual::enemy::enemy_boon_visual,
                        &all_settings::visual::enemy::enemy_boon_visual_color);
                    ImGui::Text(u8"显示武器"); ImGui::SameLine(370);
                    ImGui::Checkbox("##enemy_weapon", &all_settings::visual::enemy::enemy_weapon_visual);
                    ColorPickerWithCheckbox(u8"敌人子弹射线",
                        &all_settings::visual::enemy::enemy_weapon_glow,
                        &all_settings::visual::enemy::enemy_weapon_glow_color);
                    ImGui::Text(u8"显示距离"); ImGui::SameLine(370);
                    ImGui::Checkbox("##enemy_distance", &all_settings::visual::enemy::enemy_distance);
                });
            CreateStyledChildWindow("##enemy_preview", ImVec2(630, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"敌人效果预览");
                    ImGui::Separator();

                    ImDrawList* drawList = ImGui::GetWindowDrawList();

                    const ImVec2 previewPos = ImGui::GetCursorScreenPos();
                    const float previewWidth = 390.0f;
                    const float previewHeight = 580.0f;

                    const float boxHeight = 450.0f; // 与实际ESP一致的方框高度
                    const float boxWidth = boxHeight / 1.7f; // 与实际ESP一致的宽高比

                    const ImVec2 enemyPos = ImVec2(
                        previewPos.x + previewWidth / 2 - boxWidth / 2,
                        previewPos.y + previewHeight / 2 - boxHeight / 2 - 40
                    );

                    if (all_settings::visual::enemy::enemy_visual) {
                        if (all_settings::visual::enemy::enemy_kuang_visual) {
                            drawList->AddRect(
                                enemyPos,
                                ImVec2(enemyPos.x + boxWidth, enemyPos.y + boxHeight),
                                all_settings::visual::enemy::enemy_kuang_visual_color_ks,
                                0.0f, 0, 1.7f // 与实际ESP一致的线宽
                            );
                        }
                        if (all_settings::visual::enemy::enemy_name_visual) {
                            const char* name = "Enemy";
                            ImVec2 textSize = ImGui::CalcTextSize(name);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y - textSize.y - 2.0f
                                ),
                                all_settings::visual::enemy::enemy_name_visual_color,
                                name
                            );
                        }
                        if (all_settings::visual::enemy::enemy_ShowHealth_visual) {
                            const float health = 75.0f; // 模拟75%血量
                            const float healthHeight = boxHeight * (health / 100.0f);
                            const float healthWidth = 6.0f;

                            // 背景
                            drawList->AddRectFilled(
                                ImVec2(enemyPos.x - healthWidth - 3.0f, enemyPos.y),
                                ImVec2(enemyPos.x - 3.0f, enemyPos.y + boxHeight),
                                IM_COL32(0, 0, 0, 100)
                            );

                            // 血条
                            drawList->AddRectFilled(
                                ImVec2(enemyPos.x - healthWidth - 3.0f, enemyPos.y + boxHeight - healthHeight),
                                ImVec2(enemyPos.x - 3.0f, enemyPos.y + boxHeight),
                                all_settings::visual::enemy::enemy_Health_color
                            );

                            // 血量文字
                            std::string healthStr = std::to_string(static_cast<int>(health));
                            ImVec2 textSize = ImGui::CalcTextSize(healthStr.c_str());
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x - healthWidth - 10.0f,
                                    enemyPos.y + boxHeight / 2 - textSize.y / 2
                                ),
                                IM_COL32(255, 255, 255, 255),
                                healthStr.c_str()
                            );
                        }
                        if (all_settings::visual::enemy::enemy_boon_visual) {
                            // 模拟骨骼点位置（与实际ESP一致的比例）
                            const ImVec2 headPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.15f);
                            const ImVec2 neckPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.25f);
                            const ImVec2 pelvisPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.85f);

                            // 头部圆圈
                            drawList->AddCircle(
                                headPos,
                                5.0f,
                                all_settings::visual::enemy::enemy_boon_visual_color,
                                12,
                                1.5f
                            );

                            // 骨骼连线
                            drawList->AddLine(
                                headPos,
                                neckPos,
                                all_settings::visual::enemy::enemy_boon_visual_color,
                                1.5f
                            );

                            drawList->AddLine(
                                neckPos,
                                pelvisPos,
                                all_settings::visual::enemy::enemy_boon_visual_color,
                                1.5f
                            );
                        }
                        if (all_settings::visual::enemy::enemy_weapon_visual) {
                            const char* weapon = "AK-47";
                            ImVec2 textSize = ImGui::CalcTextSize(weapon);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y + boxHeight + 2.0f
                                ),
                                IM_COL32(255, 255, 255, 255),
                                weapon
                            );
                        }
                        if (all_settings::visual::enemy::enemy_distance) {
                            const char* distance_str = u8"10米";
                            ImVec2 textSize = ImGui::CalcTextSize(distance_str);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y + boxHeight + 22.0f
                                ),
                                IM_COL32(255, 255, 255, 255),
                                distance_str
                            );
                        }
                    }
                });            
            break;

        case VisualSubPage::TEAMMATE:
            CreateStyledChildWindow("##teammate_settings", ImVec2(210, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"启用队友透视"); ImGui::SameLine(370);
                    ImGui::Checkbox("##teammate_esp", &all_settings::visual::teammate::teammate_visual);
                    ImGui::Separator();
                    ColorPickerWithCheckbox(u8"队友方框",
                        &all_settings::visual::teammate::teammate_kuang_visual,
                        &all_settings::visual::teammate::teammate_kuang_visual_color_ks);
                    ColorPickerWithCheckbox(u8"队友名字",
                        &all_settings::visual::teammate::teammate_name_visual,
                        &all_settings::visual::teammate::teammate_name_visual_color);
                    ColorPickerWithCheckbox(u8"队友血条",
                        &all_settings::visual::teammate::teammate_ShowHealth_visual,
                        &all_settings::visual::teammate::teammate_Health_color);
                    ColorPickerWithCheckbox(u8"队友骨骼",
                        &all_settings::visual::teammate::teammate_boon_visual,
                        &all_settings::visual::teammate::teammate_boon_visual_color);
                    ImGui::Text(u8"显示武器"); ImGui::SameLine(370);
                    ImGui::Checkbox("##teammate_weapon", &all_settings::visual::teammate::teammate_weapon_visual);
                    ColorPickerWithCheckbox(u8"队友子弹射线",
                        &all_settings::visual::teammate::teammate_weapon_glow,
                        &all_settings::visual::teammate::teammate_weapon_glow_color);
                    ImGui::Text(u8"显示距离"); ImGui::SameLine(370);
                    ImGui::Checkbox("##teammate_distance", &all_settings::visual::teammate::teammate_distance);
                });
            CreateStyledChildWindow("##teammate_preview", ImVec2(630, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"队友效果预览");
                    ImGui::Separator();

                    // 获取绘制列表
                    ImDrawList* drawList = ImGui::GetWindowDrawList();

                    // 预览区域位置和大小
                    const ImVec2 previewPos = ImGui::GetCursorScreenPos();
                    const float previewWidth = 390.0f;
                    const float previewHeight = 580.0f;

                    // 模拟敌人位置（居中）
                    const float boxHeight = 450.0f; // 与实际ESP一致的方框高度
                    const float boxWidth = boxHeight / 1.7f; // 与实际ESP一致的宽高比

                    const ImVec2 enemyPos = ImVec2(
                        previewPos.x + previewWidth / 2 - boxWidth / 2,
                        previewPos.y + previewHeight / 2 - boxHeight / 2 - 40
                    );


                    // 根据左侧设置绘制对应元素
                    if (all_settings::visual::teammate::teammate_visual) {
                        if (all_settings::visual::teammate::teammate_kuang_visual) {
                            drawList->AddRect(
                                enemyPos,
                                ImVec2(enemyPos.x + boxWidth, enemyPos.y + boxHeight),
                                all_settings::visual::teammate::teammate_kuang_visual_color_ks,
                                0.0f, 0, 1.7f // 与实际ESP一致的线宽
                            );
                        }
                        if (all_settings::visual::teammate::teammate_name_visual) {
                            const char* name = "Enemy";
                            ImVec2 textSize = ImGui::CalcTextSize(name);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y - textSize.y - 2.0f
                                ),
                                all_settings::visual::teammate::teammate_name_visual_color,
                                name
                            );
                        }
                        if (all_settings::visual::teammate::teammate_ShowHealth_visual) {
                            const float health = 75.0f; // 模拟75%血量
                            const float healthHeight = boxHeight * (health / 100.0f);
                            const float healthWidth = 6.0f;

                            // 背景
                            drawList->AddRectFilled(
                                ImVec2(enemyPos.x - healthWidth - 3.0f, enemyPos.y),
                                ImVec2(enemyPos.x - 3.0f, enemyPos.y + boxHeight),
                                IM_COL32(0, 0, 0, 100)
                            );

                            // 血条
                            drawList->AddRectFilled(
                                ImVec2(enemyPos.x - healthWidth - 3.0f, enemyPos.y + boxHeight - healthHeight),
                                ImVec2(enemyPos.x - 3.0f, enemyPos.y + boxHeight),
                                all_settings::visual::teammate::teammate_Health_color
                            );

                            // 血量文字
                            std::string healthStr = std::to_string(static_cast<int>(health));
                            ImVec2 textSize = ImGui::CalcTextSize(healthStr.c_str());
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x - healthWidth - 10.0f,
                                    enemyPos.y + boxHeight / 2 - textSize.y / 2
                                ),
                                IM_COL32(255, 255, 255, 255),
                                healthStr.c_str()
                            );
                        }
                        if (all_settings::visual::teammate::teammate_boon_visual) {
                            // 模拟骨骼点位置（与实际ESP一致的比例）
                            const ImVec2 headPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.15f);
                            const ImVec2 neckPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.25f);
                            const ImVec2 pelvisPos = ImVec2(enemyPos.x + boxWidth / 2, enemyPos.y + boxHeight * 0.85f);

                            // 头部圆圈
                            drawList->AddCircle(
                                headPos,
                                5.0f,
                                all_settings::visual::teammate::teammate_boon_visual_color,
                                12,
                                1.5f
                            );

                            // 骨骼连线
                            drawList->AddLine(
                                headPos,
                                neckPos,
                                all_settings::visual::teammate::teammate_boon_visual_color,
                                1.5f
                            );

                            drawList->AddLine(
                                neckPos,
                                pelvisPos,
                                all_settings::visual::teammate::teammate_boon_visual_color,
                                1.5f
                            );
                        }
                        if (all_settings::visual::teammate::teammate_weapon_visual) {
                            const char* weapon = "AK-47";
                            ImVec2 textSize = ImGui::CalcTextSize(weapon);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y + boxHeight + 2.0f
                                ),
                                IM_COL32(255, 255, 255, 255),
                                weapon
                            );
                        }
                        if (all_settings::visual::teammate::teammate_distance) {
                            const char* distance_str = u8"10米";
                            ImVec2 textSize = ImGui::CalcTextSize(distance_str);
                            drawList->AddText(
                                ImVec2(
                                    enemyPos.x + boxWidth / 2 - textSize.x / 2,
                                    enemyPos.y + boxHeight + 22.0f
                                ),
                                IM_COL32(255, 255, 255, 255),
                                distance_str
                            );
                        }
                    }
                });
            break;

        case VisualSubPage::LOCAL:
            // 本地设置面板
            CreateStyledChildWindow("##local_settings", ImVec2(210, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"本地视角设置");
                    ImGui::Separator();
                    IconCheckbox("aimbot", u8"开启第三人称", (ImTextureID)g_textures[3], ImVec2(25, 25),
                        all_settings::visual::local::self::ThirdPerson.enabled, ImVec2(330, 100),
                        []() {
                            // 目标模式选择
                            ImGui::Text("目标模式:");
                            ImGui::SameLine(220);
                            ImGui::PushItemWidth(100);
                            int ThirdPerson_mode = static_cast<int>(all_settings::visual::local::self::ThirdPerson.mode);
                            if (ImGui::Combo("##aim_mode", &ThirdPerson_mode, "always\0targe\0hold\0")) {
                                all_settings::visual::local::self::ThirdPerson.mode =
                                    static_cast<all_settings::targe_hole>(ThirdPerson_mode);
                            }
                            ImGui::PopItemWidth();
                            ImGui::Text("快捷键:");
                            ImGui::SameLine(230);
                            KeySelector("ThirdPerson_kjj", "ThirdPerson_kjj_open", all_settings::visual::local::self::ThirdPerson.hotkey);
                        });
                    ImGui::Text(u8"视野范围"); ImGui::SameLine(370);
                    ImGui::Checkbox("##player_fov", &all_settings::visual::local::self::player_fov);
                    if (all_settings::visual::local::self::player_fov)
                    {
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##player_fov_fw", &all_settings::visual::local::self::player_fov_fw, 50.0f, 150.0f, "%.0f");
                    }
                    ColorPickerWithCheckbox(u8"子弹轨迹", &all_settings::visual::local::self::weapon_glow,
                        &all_settings::visual::local::self::weapon_glow_color);
                    IconCheckbox("show_crosshair", u8"准心", (ImTextureID)g_textures[3], ImVec2(25, 25),
                        all_settings::visual::local::self::show_crosshair, ImVec2(330, 520),
                        []() {
                            ImGui::Text(u8"颜色1:");
                            ImGui::SameLine(290);
                            bool changed = false;
                            if (ImGui::ColorButton("##crosshair_color_1", all_settings::visual::local::self::crosshair_color_1)) {
                                ImGui::OpenPopup("##crosshair_color_1_picker1");
                            }
                            if (ImGui::BeginPopup("##crosshair_color_1_picker1")) {
                                changed |= ImGui::ColorPicker4(
                                    "##picker1",
                                    (float*)&all_settings::visual::local::self::crosshair_color_1,
                                    ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayRGB
                                );
                                ImGui::EndPopup();
                            }
                            ImGui::Text(u8"颜色2:");
                            ImGui::SameLine(290);
                            if (ImGui::ColorButton("##crosshair_color_2", all_settings::visual::local::self::crosshair_color_2)) {
                                ImGui::OpenPopup("##crosshair_color_2_picker1");
                            }
                            if (ImGui::BeginPopup("##crosshair_color_2_picker1")) {
                                changed |= ImGui::ColorPicker4(
                                    "##picker1",
                                    (float*)&all_settings::visual::local::self::crosshair_color_2,
                                    ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayRGB
                                );
                                ImGui::EndPopup();
                            }
                            ImGui::Text(u8"准心长度");
                            ImGui::PushItemWidth(300);
                            ImGui::SliderFloat("##crosshair_Length", &all_settings::visual::local::self::crosshair_Length, 100.0f, 500.0f, "%.0f");
                            ImGui::Text(u8"准心中心点直径");
                            ImGui::PushItemWidth(300);
                            ImGui::SliderFloat("##crosshair_center_lenth", &all_settings::visual::local::self::crosshair_center_lenth, 0.0f, 5.0f, "%.1f");
                            ImGui::Text(u8"准心中心间距");
                            ImGui::PushItemWidth(300);
                            ImGui::SliderFloat("##crosshair_gap", &all_settings::visual::local::self::crosshair_gap, 0.0f, 50.0f, "%.1f");
                            ImGui::Text(u8"准心最小线宽");
                            ImGui::PushItemWidth(300);
                            ImGui::SliderFloat("##crosshair_minThickness", &all_settings::visual::local::self::crosshair_minThickness, 0.5f, 5.0f, "%.1f");
                            ImGui::Text(u8"准心最大线宽");
                            ImGui::PushItemWidth(300);
                            ImGui::SliderFloat("##crosshair_maxThickness", &all_settings::visual::local::self::crosshair_maxThickness, 0.5f, 5.0f, "%.1f");

                        });
                    ImGui::Text(u8"移除开镜缩放"); ImGui::SameLine(370);
                    ImGui::Checkbox("##remove_Scoped_fov", &all_settings::visual::local::self::remove_Scoped_fov);
                    if (all_settings::visual::local::self::remove_Scoped_fov)
                    {
                        ImGui::Text(u8"开镜缩放大小");
                        ImGui::PushItemWidth(380);
                        ImGui::SliderFloat("##Scoped_fov", &all_settings::visual::local::self::Scoped_fov, 20.0f, 90.0f, "%.0f");
                    }
                    ImGui::Text(u8"移除开镜黑框"); ImGui::SameLine(370);
                    ImGui::Checkbox("##remove_Scoped_blachk", &all_settings::visual::local::self::remove_Scoped_blachk);
                });
            CreateStyledChildWindow("##world_settings", ImVec2(630, 10), ImVec2(410, 610),
                ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
                ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
                []() {
                    ImGui::Text(u8"世界设置");
                    ImGui::Separator();
                    ColorPickerWithCheckbox(u8"世界颜色",
                        &all_settings::visual::local::world::draw_world_color,
                        &all_settings::visual::local::world::world_color);
                    ImGui::Text(u8"移除天空盒"); ImGui::SameLine(370);
                    ImGui::Checkbox("##remove_3d_skybos", &all_settings::visual::local::world::remove_3d_skybos);
                    ColorPickerWithCheckbox(u8"绘制fov",
                        &all_settings::visual::local::world::draw_fov,
                        &all_settings::visual::local::world::fov_color);
                    ImGui::Text(u8"绘制C4"); ImGui::SameLine(370);
                    ImGui::Checkbox("##draw_C4_time", &all_settings::visual::local::world::draw_C4_time);
                    ImGui::Separator();
                    ImGui::Text(u8"投掷物效果移除");
                    ImGui::Separator();
                    ImGui::Text(u8"移除效果:");
                    ImGui::SameLine(190);
                    ImGui::PushItemWidth(205);
                    ImGuiStyle& style = ImGui::GetStyle();
                    float original_padding = style.FramePadding.x;
                    style.FramePadding.x = 10.0f;
                    std::string effects_str;
                    auto& gs = all_settings::visual::local::world::grenade_settings;
                    if (gs.removeFlash) effects_str += u8"闪光弹 ";
                    if (gs.removeSmoke) effects_str += u8"烟雾弹 ";
                    if (gs.removeBlood) effects_str += u8"血迹 ";
                    if (gs.removeBulletImpacts) effects_str += u8"弹痕 ";
                    if (gs.removeShellCasings) effects_str += u8"弹壳 ";
                    if (effects_str.empty()) effects_str = u8"未选择";
                    if (ImGui::BeginCombo("##grenade_effects", effects_str.c_str())) {
                        // 投掷物效果
                        ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.0f, 1.0f), u8"--- 投掷物 ---");
                        ImGui::Selectable(u8"闪光弹", &gs.removeFlash, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"烟雾弹", &gs.removeSmoke, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.0f, 1.0f), u8"--- 其他效果 ---");
                        ImGui::Selectable(u8"血迹", &gs.removeBlood, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"弹痕", &gs.removeBulletImpacts, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"弹壳", &gs.removeShellCasings, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::EndCombo();
                    }
                    style.FramePadding.x = original_padding;
                    ImGui::PopItemWidth();

                    ImGui::Separator();
                    ImGui::Text(u8"世界效果移除");
                    ImGui::Separator();

                    ImGui::Text(u8"移除效果:");
                    ImGui::SameLine(190);
                    ImGui::PushItemWidth(205);

                    // 保存原始样式
                    style.FramePadding.x = 10.0f;

                    // 构建世界效果字符串
                    std::string world_effects;
                    auto& ws = all_settings::visual::local::world::world_settings;
                    if (ws.removeShadows) world_effects += u8"阴影 ";
                    if (ws.removeWorldLighting) world_effects += u8"光照 ";
                    if (ws.removeFog) world_effects += u8"雾效 ";
                    if (ws.removeWeather) world_effects += u8"天气 ";
                    if (ws.removeParticles) world_effects += u8"粒子 ";
                    if (world_effects.empty()) world_effects = u8"未选择";

                    if (ImGui::BeginCombo("##world_effects", world_effects.c_str())) {
                        // 光照与阴影
                        ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.0f, 1.0f), u8"--- 光照与阴影 ---");
                        ImGui::Selectable(u8"阴影", &ws.removeShadows, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"世界光照", &ws.removeWorldLighting, ImGuiSelectableFlags_DontClosePopups);

                        // 环境效果
                        ImGui::TextColored(ImVec4(1.0f, 0.8f, 0.0f, 1.0f), u8"--- 环境效果 ---");
                        ImGui::Selectable(u8"雾效", &ws.removeFog, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"天气", &ws.removeWeather, ImGuiSelectableFlags_DontClosePopups);
                        ImGui::Selectable(u8"粒子", &ws.removeParticles, ImGuiSelectableFlags_DontClosePopups);

                        ImGui::EndCombo();
                    }

                    // 恢复样式
                    style.FramePadding.x = original_padding;
                    ImGui::PopItemWidth();

                });
            break;
        }
    }

    void RenderSkinPage() {
        CreateStyledChildWindow("##movement_ys", ImVec2(10, 10), ImVec2(350, 310),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), u8"移动功能");
                ImGui::Separator();
                ImGui::Text(u8"连跳");ImGui::SameLine(310);
                ImGui::Checkbox("##bunny_hop", &all_settings::skin::movement::bunny_bhop);
                ImGui::Text(u8"空中转向");ImGui::SameLine(310);
                ImGui::Checkbox("##auto_space_turn", &all_settings::skin::movement::auto_space_turn);
                //ImGui::Text(u8"慢走");ImGui::SameLine(310);
                //ImGui::Checkbox("##slowwalk", &all_settings::skin::movement::slowwalk);
                //ImGui::PushItemWidth(320);
                //ImGui::SliderFloat("##slowwalk_speed", &all_settings::skin::movement::slowwalk_speed, 0.0f, 100.0f, "%.0f");
                //ImGui::PopItemWidth();
                ImGui::Text(u8"快速急停");ImGui::SameLine(310);
                ImGui::Checkbox("##standalone_quick_stop", &all_settings::skin::movement::standalone_quick_stop);
            });

        CreateStyledChildWindow("##voice", ImVec2(10, 330), ImVec2(350, 290),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), u8"声音");
                ImGui::Separator();
                ImGui::Text(u8"击中音效");ImGui::SameLine(310);
                ImGui::Checkbox("##hit_sound", &all_settings::skin::voice::hit_sound);
                ImGui::Text(u8"音效选择");ImGui::SameLine(180);
                ImGui::PushItemWidth(155);
                ImGuiStyle& style = ImGui::GetStyle();
                float original_padding = style.FramePadding.x;
                style.FramePadding.x = 10.0f;
                if (ImGui::Combo("##hit_sound_t", &all_settings::skin::voice::hit_sound_index, all_settings::skin::voice::hit_sound_t, IM_ARRAYSIZE(all_settings::skin::voice::hit_sound_t)))
                {
                    // Hit Sound
                    switch (all_settings::skin::voice::hit_sound_index)
                    {
                    case 0:
                        PlaySoundA(reinterpret_cast<char*>(neverlose_sound), NULL, SND_ASYNC | SND_MEMORY);
                        break;
                    case 1:
                        PlaySoundA(reinterpret_cast<char*>(Fuck), NULL, SND_ASYNC | SND_MEMORY);
                        break;
                    case 2:
                        PlaySoundA(reinterpret_cast<char*>(Senpai), NULL, SND_ASYNC | SND_MEMORY);
                        break;
                    case 3:
                        PlaySoundA(reinterpret_cast<char*>(skeet_sound), NULL, SND_ASYNC | SND_MEMORY);
                        break;
                    default:
                        break;
                    }
                };
                ImGui::PopItemWidth();
                style.FramePadding.x = original_padding;
                ImGui::Text(u8"击中提示");ImGui::SameLine(310);
                ImGui::Checkbox("##hit_message", &all_settings::skin::voice::hit_message);
                ImGui::Text(u8"击杀发言(不填的话默认)");ImGui::SameLine(310);
                ImGui::Checkbox("##hit_death_message", &all_settings::skin::voice::hit_death_message);
                if (all_settings::skin::voice::hit_death_message)
                {
                    ImGui::Text(u8"你被");
                    ImGui::SameLine();
                    ImGui::PushItemWidth(70);
                    ImGui::InputText(u8"##killer_name", all_settings::skin::voice::killerName, IM_ARRAYSIZE(all_settings::skin::voice::killerName));
                    ImGui::SameLine();
                    ImGui::Text(u8"用");
                    ImGui::SameLine();
                    ImGui::PushItemWidth(70);
                    ImGui::InputText(u8"##weapon_name", all_settings::skin::voice::weaponName, IM_ARRAYSIZE(all_settings::skin::voice::weaponName));
                    ImGui::SameLine();
                    ImGui::Text(u8"杀死");
                }
            });

        CreateStyledChildWindow("##movement_ys1", ImVec2(370, 10), ImVec2(330, 610),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), u8"发言管理");
                ImGui::Separator();
                static int selectedContentIndex = -1;
                static char newContentBuffer[256] = "";
                ImGui::Text(u8"启用语音功能");ImGui::SameLine(290);
                ImGui::Checkbox("##open_Speech", &all_settings::skin::Speech::open_Speech);
                ImGui::Separator();
                
                // 获取实际的内容数量
                int contentCount = all_settings::skin::Speech::savedContents.size();

                // 显示标题
                ImGui::Text(u8"已保存的发言 (%d):", contentCount);

                // 内容列表区域
                ImGui::BeginChild("##content_list", ImVec2(-FLT_MIN, 200), true);

                if (contentCount == 0) {
                    // 清空选中状态
                    selectedContentIndex = -1;
                }
                else {
                    for (int i = 0; i < contentCount; i++) {
                        bool isSelected = (selectedContentIndex == i);
                        ImGui::PushID(i);
                        if (ImGui::Selectable(all_settings::skin::Speech::savedContents[i].c_str(), isSelected)) {
                            selectedContentIndex = i;
                        }
                        ImGui::PopID();
                    }
                }
                ImGui::EndChild();

                // 添加新内容区域
                ImGui::Separator();
                ImGui::Text(u8"添加新发言:");
                ImGui::InputText("##new_content", newContentBuffer, IM_ARRAYSIZE(newContentBuffer));

                if (ImGui::Button(u8"添加", ImVec2(80, 30))) {
                    all_settings::skin::Speech::addContent(newContentBuffer);
                }

                ImGui::SameLine();

                // 删除选中内容按钮
                if (selectedContentIndex >= 0) {
                    if (ImGui::Button(u8"删除选中", ImVec2(95, 30))) {
                        all_settings::skin::Speech::removeContent(selectedContentIndex);
                    }
                }
                else {
                    ImGui::BeginDisabled();
                    ImGui::Button(u8"删除选中", ImVec2(95, 30));
                    ImGui::EndDisabled();
                }

                ImGui::SameLine();

                // 清空所有内容按钮
                if (ImGui::Button(u8"清空全部", ImVec2(95, 30))) {
                    all_settings::skin::Speech::savedContents.clear();
                    selectedContentIndex = -1;
                }
                ImGui::Text(u8"发言模式");
                ImGui::SameLine(165);
                ImGui::PushItemWidth(150);
                int current_mode = static_cast<int>(all_settings::skin::Speech::Speech_mode);
                if (ImGui::Combo("##aim_mode", &current_mode, "顺序发送\0随机发送\0")) {
                    all_settings::skin::Speech::Speech_mode =
                        static_cast<all_settings::skin::Speech::SpeechMode>(current_mode);
                }

            });

        CreateStyledChildWindow("##movement_ys2", ImVec2(710, 10), ImVec2(330, 610),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), u8"菜单设置");
                ImGui::Separator();
                ImGui::Text(u8"菜单快捷键");ImGui::SameLine(230);
                KeySelector("menu_kjj", "menu_kjj_open", all_settings::skin::menu_steeing::menu_kjj);
            });
    }

    void RenderSettingsPage() {

        // 文件列表窗口
        CreateStyledChildWindow("##cansu_setting", ImVec2(10, 10), ImVec2(510, 610),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::Text(u8"参数设置");
                ImGui::Separator();
                // 文件列表
                ImGui::BeginChild("##cfg_list_child", ImVec2(-FLT_MIN, 400), true);
                {
                    for (int i = 0; i < static_cast<int>(cfgFiles.size()); i++) {
                        const bool isSelected = (selectedCfgIndex == i);

                        // 为每个选项添加内边距
                        ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.0f, 0.5f));
                        ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(20.0f, 18.0f));
                        // 移除文件扩展名
                        std::filesystem::path filePath(cfgFiles[i]);
                        std::string fileNameWithoutExtension = filePath.stem().string();

                        if (ImGui::Selectable(fileNameWithoutExtension.c_str(), isSelected)) {
                            selectedCfgIndex = i;
                        }
                        ImGui::PopStyleVar(2);

                        if (isSelected) {
                            ImGui::SetItemDefaultFocus();
                        }
                    }
                }
                ImGui::EndChild();
            });

        // 操作窗口
        CreateStyledChildWindow("##cansu_caozuo_setting", ImVec2(530, 10), ImVec2(510, 610),
            ImVec4(0.127f, 0.198f, 0.348f, 0.912f),
            ImVec4(0.2f, 0.6f, 0.9f, 0.5f),
            []() {
                ImGui::Text(u8"参数设置");
                ImGui::Separator();
                ImGui::Text(u8"配置文件名称");
                // 尝试修改为使用明确的ID
                ImGui::InputText("##config_name_input", newCfgName, IM_ARRAYSIZE(newCfgName));

                // 创建按钮 - 单独一行
                if (ImGui::Button(u8"创建", ImVec2(-FLT_MIN, 60))) {
                    if (strlen(newCfgName) > 0) {
                        std::string folderPath = "C:\\Sy_Hex";
                        std::string fullPath = folderPath + "\\" + std::string(newCfgName) + ".cfg";

                        // 检查文件名是否合法（不包含非法字符）
                        if (std::string(newCfgName).find_first_of("\\/:*?\"<>|") != std::string::npos) {
                            MessageBoxA(NULL, "文件名包含非法字符", "错误", MB_ICONERROR);
                        }
                        else {
                            // 检查文件夹是否存在，不存在则创建
                            if (!fs::exists(folderPath)) {
                                if (!fs::create_directories(folderPath)) {
                                    MessageBoxA(NULL, "无法创建配置文件夹", "错误", MB_ICONERROR);
                                    return;
                                }
                            }

                            // 检查文件是否已存在
                            if (fs::exists(fullPath)) {
                                MessageBoxA(NULL, "配置文件已存在", "错误", MB_ICONERROR);
                            }
                            else {
                                // 创建配置文件（使用默认配置）
                                resetConfigToDefault(); // 重置为默认配置
                                saveConfig(newCfgName); // 保存默认配置

                                // 刷新文件列表
                                scanCfgFiles();

                                // 清空输入框
                                memset(newCfgName, 0, sizeof(newCfgName));

                                // 选中新创建的文件
                                for (int i = 0; i < cfgFiles.size(); i++) {
                                    if (cfgFiles[i] == std::string(newCfgName) + ".cfg") {
                                        selectedCfgIndex = i;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else {
                        MessageBoxA(NULL, "请输入配置文件名", "错误", MB_ICONERROR);
                    }
                }

                // 加载按钮 - 单独一行
                if (ImGui::Button(u8"加载", ImVec2(-FLT_MIN, 60)) && selectedCfgIndex >= 0) {
                    std::string selectedFile = cfgFiles[selectedCfgIndex];
                    std::string selectedFilename = selectedFile.substr(0, selectedFile.find_last_of('.'));
                    currentlyLoadedConfig = selectedFilename;
                    loadConfig(currentlyLoadedConfig);
                }

                if (ImGui::Button(u8"保存", ImVec2(-FLT_MIN, 60)) && selectedCfgIndex >= 0) {
                    std::string selectedFile = cfgFiles[selectedCfgIndex];
                    std::string selectedFilename = selectedFile.substr(0, selectedFile.find_last_of('.'));

                    // 检查是否未加载任何文件
                    if (currentlyLoadedConfig.empty()) {
                        // 未加载任何文件，直接跳过不做任何操作
                        return;
                    }

                    // 更严格的字符串比较
                    bool isSameFile = (selectedFilename == currentlyLoadedConfig);

                    if (!isSameFile) {
                        // 不一致，设置弹窗信息并显示
                        pendingSaveFilename = selectedFilename;
                        pendingSaveMessage = "您要保存的文件(" + selectedFile + ")与当前加载的文件(" + currentlyLoadedConfig + ".cfg)不同，是否继续保存？";
                        showSaveConfirmDialog = true;
                    }
                    else {
                        // 一致，直接保存
                        saveConfig(selectedFilename);
                        currentlyLoadedConfig = selectedFilename;

                        // 显示保存成功提示
                        showSaveSuccess = true;
                        saveSuccessAlpha = 1.0f;
                        saveSuccessTime = std::chrono::steady_clock::now();
                    }
                }
                // 删除按钮 - 单独一行
                if (ImGui::Button(u8"删除", ImVec2(-FLT_MIN, 60)) && selectedCfgIndex >= 0) {
                    pendingDeleteFilename = cfgFiles[selectedCfgIndex];
                    showDeleteConfirmDialog = true;
                }


                // 修改重置按钮的代码
                if (ImGui::Button(u8"重置", ImVec2(-FLT_MIN, 60))) {
                    if (selectedCfgIndex >= 0) {
                        showResetConfirmDialog = true;
                    }
                    else {
                        // 可以在这里添加提示，告诉用户需要先选择一个配置文件
                    }
                }
                if (ImGui::Button(u8"刷新列表", ImVec2(-FLT_MIN, 60)))
                {
                    scanCfgFiles();
                }
            });
    }

    void RenderEmptyPage() {
        ImGui::SetCursorPos(ImVec2(350, 220));
        ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), u8"请选择上方功能按钮开始使用");
    }

    void Screenui()
    {
        float alphaAnim = MenuAnimationManager::GetAlpha();

        // 全屏背景层 - 使用动画透明度
        ImGui::SetNextWindowPos({ 0, 0 });
        ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
        ImGui::Begin("##Background", nullptr,
            ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoResize |
            ImGuiWindowFlags_NoMove |
            ImGuiWindowFlags_NoBackground |
            ImGuiWindowFlags_NoBringToFrontOnFocus);

        auto draw = ImGui::GetWindowDrawList();
        draw->AddRectFilled(
            { 0, 0 },
            ImGui::GetIO().DisplaySize,
            ImColor(0, 0, 0, static_cast<int>(30 * alphaAnim)) // 动态透明度
        );
        ImGui::End();

        // 主界面窗口 - 设置初始位置（仅第一次）
        if (firstTime) {
            ImVec2 displaySize = ImGui::GetIO().DisplaySize;
            ImVec2 windowPos = ImVec2(displaySize.x * 0.5f - 1100 * 0.5f, displaySize.y * 0.5f - 800 * 0.5f);
            ImGui::SetNextWindowPos(windowPos, ImGuiCond_Appearing);
            firstTime = false;
        }

        // 设置主窗口样式
        ImGuiStyle& style = ImGui::GetStyle();
        style.FramePadding.y = 1.0f;
        ImGui::SetNextWindowSize({ 1100, 800 }, ImGuiCond_Always);

        // 使用透明度动画开始主窗口
        ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alphaAnim);
        ImGui::Begin("##Screen", nullptr,
            ImGuiWindowFlags_NoCollapse |
            ImGuiWindowFlags_NoResize |
            ImGuiWindowFlags_NoTitleBar |
            ImGuiWindowFlags_NoScrollbar |
            ImGuiWindowFlags_NoScrollWithMouse | // 禁用鼠标滚动
            ImGuiWindowFlags_NoBackground);

        // 获取窗口位置和大小
        ImVec2 windowPos = ImGui::GetWindowPos();
        windowSize = ImVec2(ImGui::GetWindowSize().x - 25, ImGui::GetWindowSize().y - 25);

        // 参数配置（动态透明度）
        const float cornerRadius = 15.0f;
        const float borderWidth = 1.0f;
        const float glowSize = 25.0f;
        ImColor backgroundColor(37, 59, 96, static_cast<int>(255 * alphaAnim));
        ImColor borderColor(150, 150, 150, static_cast<int>(255 * alphaAnim));
        ImColor glowColor(200, 200, 200, static_cast<int>(225 * alphaAnim));

        draw = ImGui::GetWindowDrawList();

        // 绘制发光层和背景（动态透明度）
        const int glowLayers = 20;
        for (int i = 0; i < glowLayers; i++) {
            float progress = (i + 1) / float(glowLayers);
            float alpha = glowColor.Value.w * pow(1.0f / 1.2f, glowLayers - i - 1) * alphaAnim;
            float offset = glowSize * (1.0f - progress);
            float dynamicRadius = cornerRadius + offset * 0.5f;

            draw->AddRectFilled(
                ImVec2(windowPos.x + 25 - offset, windowPos.y + 25 - offset),
                ImVec2(windowPos.x + windowSize.x + offset, windowPos.y + windowSize.y + offset),
                ImColor(glowColor.Value.x, glowColor.Value.y, glowColor.Value.z, alpha),
                dynamicRadius,
                ImDrawFlags_RoundCornersAll
            );
        }

        // 主背景和边框
        draw->AddRectFilled(
            ImVec2(windowPos.x + 25, windowPos.y + 25),
            ImVec2(windowPos.x + windowSize.x, windowPos.y + windowSize.y),
            backgroundColor,
            cornerRadius,
            ImDrawFlags_RoundCornersAll
        );

        draw->AddRect(
            ImVec2(windowPos.x + 25, windowPos.y + 25),
            ImVec2(windowPos.x + windowSize.x, windowPos.y + windowSize.y),
            borderColor,
            cornerRadius,
            ImDrawFlags_RoundCornersAll,
            borderWidth
        );

        RenderNavigationBar(ImVec2(windowPos.x + 25, windowPos.y + 25));
        RenderContentArea();
        RenderFooter();
        // 修改重置确认对话框
        if (showResetConfirmDialog) {
            ImGui::OpenPopup("确认重置");
            if (ImGui::BeginPopupModal("确认重置", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
                ImGui::Text("确定要将配置文件 %s 重置为默认设置吗？", cfgFiles[selectedCfgIndex].c_str());
                ImGui::Separator();

                if (ImGui::Button("确定", ImVec2(120, 0))) {
                    resetSelectedConfigToDefault();
                    showResetConfirmDialog = false;
                    ImGui::CloseCurrentPopup();
                }
                ImGui::SameLine();
                if (ImGui::Button("取消", ImVec2(120, 0))) {
                    showResetConfirmDialog = false;
                    ImGui::CloseCurrentPopup();
                }
                ImGui::EndPopup();
            }
        }
        // 保存确认对话框
        if (showSaveConfirmDialog) {
            ImGui::OpenPopup("确认保存");
            if (ImGui::BeginPopupModal("确认保存", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
                ImGui::TextUnformatted(pendingSaveMessage.c_str());
                ImGui::Separator();

                if (ImGui::Button("是", ImVec2(120, 0))) {
                    // 用户选择"是"，执行保存
                    saveConfig(pendingSaveFilename);
                    currentlyLoadedConfig = pendingSaveFilename;
                    showSaveConfirmDialog = false;

                    // 设置保存成功提示
                    showSaveSuccess = true;
                    saveSuccessAlpha = 1.0f;
                    saveSuccessTime = std::chrono::steady_clock::now();

                    ImGui::CloseCurrentPopup();
                }
                ImGui::SameLine();
                if (ImGui::Button("否", ImVec2(120, 0))) {
                    // 用户选择"否"，不执行保存
                    showSaveConfirmDialog = false;
                    ImGui::CloseCurrentPopup();
                }
                ImGui::EndPopup();
            }
        }
        // 删除确认对话框
        if (showDeleteConfirmDialog) {
            ImGui::OpenPopup("确认删除");
            if (ImGui::BeginPopupModal("确认删除", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
                ImGui::Text("确定要删除配置文件 %s 吗？此操作不可恢复！", pendingDeleteFilename.c_str());
                ImGui::Separator();

                if (ImGui::Button("确定", ImVec2(120, 0))) {
                    std::string fullPath = "C:\\Sy_Hex\\" + pendingDeleteFilename;
                    if (DeleteFileA(fullPath.c_str())) {
                        cfgFiles.erase(cfgFiles.begin() + selectedCfgIndex);
                        selectedCfgIndex = -1;
                    }
                    showDeleteConfirmDialog = false;
                    ImGui::CloseCurrentPopup();
                }
                ImGui::SameLine();
                if (ImGui::Button("取消", ImVec2(120, 0))) {
                    showDeleteConfirmDialog = false;
                    ImGui::CloseCurrentPopup();
                }
                ImGui::EndPopup();
            }
        }
        // 在渲染循环中添加（放在ImGui渲染代码的合适位置）
        if (showLoadSuccess) {
            // 计算已经过去的时间
            auto now = std::chrono::steady_clock::now();
            auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - loadSuccessTime).count();

            // 如果超过1.5秒，开始淡出
            if (elapsed > 1500) {
                loadSuccessAlpha -= 0.01f; // 调整这个值可以改变淡出速度
                if (loadSuccessAlpha <= 0.0f) {
                    loadSuccessAlpha = 0.0f;
                    showLoadSuccess = false;
                }
            }

            // 设置窗口透明度和位置
            ImGui::SetNextWindowBgAlpha(loadSuccessAlpha);
            ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 20, 20), ImGuiCond_Always, ImVec2(1.0f, 0.0f));

            // 创建提示窗口
            if (ImGui::Begin("LoadSuccess", nullptr,
                ImGuiWindowFlags_NoDecoration |
                ImGuiWindowFlags_AlwaysAutoResize |
                ImGuiWindowFlags_NoSavedSettings |
                ImGuiWindowFlags_NoFocusOnAppearing |
                ImGuiWindowFlags_NoNav))
            {
                ImGui::TextColored(ImVec4(0.0f, 1.0f, 0.0f, loadSuccessAlpha), u8"配置加载成功");
            }
            ImGui::End();
        }
        ImGui::End();
        ImGui::PopStyleVar();
    }
}